package com.project.finance.version.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.project.finance.common.mapper.TbVersionMapper;
import com.project.finance.common.po.TbVersion;
import com.project.finance.common.vo.ResultMsg;
import com.project.finance.version.service.AppVersionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: Brendan Li
 * @description
 * @Date: 2019/12/06/14:48
 */
@Service
public class AppVersionServiceImpl implements AppVersionService {


    @Autowired
    private TbVersionMapper tbVersionMapper;

    @Override
    public TbVersion getVersion(int id) {
        TbVersion tbVersion = tbVersionMapper.selectByPrimaryKey(id);
        return tbVersion;
    }

    @Override
    public List<TbVersion> selectAll() {
        return tbVersionMapper.selectAll();
    }

    @Override
    public int update(TbVersion tbVersion) {
        return tbVersionMapper.updateByPrimaryKey(tbVersion);
    }

    @Override
    public ResultMsg listVersionByPage(int pageSize, int pageNum) {
        ResultMsg resultMsg = new ResultMsg();

        PageHelper.startPage(pageNum,pageSize);

        List<TbVersion> tbVersions = tbVersionMapper.selectAll();

        //获取结果集的分页信息
        PageInfo pageInfo =new PageInfo(tbVersions);
        //获取总记录数
        long total = pageInfo.getTotal();
        resultMsg.setTatol(total);
        resultMsg.setData(tbVersions);
        return resultMsg;
    }
}
